package al.xc.common.util;

public class SelfThreadLocal<T> {

    public interface Maker<T> {
        T make();
    }

    private Maker<T> maker_ = null;
    private ThreadLocal<T> value_ = null;

    public SelfThreadLocal(Maker<T> maker) {
        value_ = new ThreadLocal<>();
        maker_ = maker;
    }
    public T get() {
        if (null == value_.get()) {
            value_.set(maker_.make());
        }
        return value_.get();
    }
}